﻿<html>
	<head>
	</head>
	
	<body>
		<input id="testinput" type="text" />

<script type="text/javascript">
        function addEvent(el,name,fn){
            if(el.addEventListener) return el.addEventListener(name,fn,false);
            return el.attachEvent('on'+name,fn);
        }
        function fireEvent(element,event,keyCode){
            if (document.createEventObject){
                var evt = document.createEventObject();
                evt.keyCode = keyCode;
                return element.fireEvent('on'+event,evt);
            }else{
                var evt = document.createEvent("HTMLEvents");
                evt.initEvent(event, true, true );
                evt.keyCode = keyCode;
                return !element.dispatchEvent(evt);
            }
        }
        var input = document.getElementById('testinput');
        addEvent(input,'keydown',function(evt){
            alert('program fired');
            if(evt.keyCode == 13){
                alert('entered');
            }
        });
        fireEvent(input,'keydown',13);
    </script>
	</body>
</html>